package com.qianjiang.module.lib_common.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class PreferenceUtil {
   
	/**获取本应用的SharePreferences
	 * @param mContext
	 * @return
	 */
	private static SharedPreferences getPreferences(Context mContext){
		String preferenceName="千匠星云";
		return mContext.getSharedPreferences(preferenceName, Context.MODE_PRIVATE);
	}
	/**
	 * 设置float类型的值
	 * @param key     键
	 * @param value 值
	 * @param mContext
	 */
	public static void setIntValue(String key, int value , Context mContext){
		
		SharedPreferences preferences=getPreferences(mContext);
	    Editor editor =preferences.edit();
	    editor.putInt(key, value);
	    editor.commit();
	}
	
	/**
	 * 获取int类型的值
	 * @param key     键
	 * @param value 默认值
	 * @param mContext
	 */
	public static int getIntValue(String key, int value, Context mContext){
		SharedPreferences preferences=getPreferences(mContext);
		return preferences.getInt(key, value);
	}
	
	/**
	 * 设置boolean类型的值
	 * @param key     键
	 * @param value 值
	 * @param mContext 
	 */
	public static void setBooleanValue(String key, boolean value, Context mContext){
		SharedPreferences preferences=getPreferences(mContext);
	    Editor editor =preferences.edit();
	    editor.putBoolean(key, value);
	    editor.commit();
		
	}
	
	/**
	 * 获取Boolean类型的值
	 * @param key     键
	 * @param value 默认值
	 * @param mContext 
	 */
	public static boolean getBooleanValue(String key, boolean value, Context mContext){
		SharedPreferences preferences = getPreferences(mContext);
		return preferences.getBoolean(key, value);
	}
	
	/**
	 * 设置String类型的值
	 * @param key     键
	 * @param value 值
	 * @param mContext 
	 */
	public static void setStringValue(String key, String value, Context mContext){
		SharedPreferences preferences=getPreferences(mContext);
	    Editor editor =preferences.edit();
	    editor.putString(key, value);
	    editor.commit();
	}
	
	/**
	 * 获取String类型的值
	 * @param key     键
	 * @param value 默认值
	 * @param mContext 
	 */
	public static String getStringValue(String key, String value, Context mContext){
		SharedPreferences preferences = getPreferences(mContext);
		return preferences.getString(key, value);
	}
	
	/**
	 * 设置float类型的值
	 * @param key     键
	 * @param value 值
	 * @param mContext
	 */
	public static void setFloatValue(String key, float value, Context mContext){
		SharedPreferences preferences=getPreferences(mContext);
	    Editor editor =preferences.edit();
	    editor.putFloat(key, value);
	    editor.commit();
		
	}
	
	/**
	 * 获取float类型的值
	 * @param key     键
	 * @param value 默认值
	 * @param mContext
	 */
	public static float getFloatValue(String key, float value, Context mContext){
		SharedPreferences preferences = getPreferences(mContext);
		return preferences.getFloat(key, value);
	}


	/**
	 * 设置float类型的值
	 * @param key     键
	 * @param value 值
	 * @param mContext
	 */
	public static void setLongValue(String key, long value, Context mContext){
		SharedPreferences preferences=getPreferences(mContext);
		Editor editor =preferences.edit();
		editor.putLong(key, value);
		editor.commit();

	}

	/**
	 * 获取float类型的值
	 * @param key     键
	 * @param value 默认值
	 * @param mContext
	 */
	public static long getLongValue(String key, long value, Context mContext){
		SharedPreferences preferences = getPreferences(mContext);
		return preferences.getLong(key, value);
	}

	public static void clearSharePref(Context context) {
		SharedPreferences preferences = getPreferences(context);
		Editor editor = preferences.edit();
		editor.clear();
		editor.commit();
	}
	
}
